/*
Copyright (c) 2008  Franklin Schmidt <fschmidt@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

package fschmidt.db.extend;

import java.sql.Connection;
import java.sql.SQLException;
import fschmidt.db.DbObject;
import fschmidt.db.DbKey;
import fschmidt.db.DbKeySetter;
import fschmidt.db.DbObjectFactory;
import fschmidt.db.DbArcana;
import fschmidt.db.SQLRuntimeException;
import fschmidt.db.LongKey;
import fschmidt.db.StringKey;


public class FilterDatabase extends DbDatabaseExt {
	protected final DbDatabaseExt database;

	public FilterDatabase(DbDatabaseExt database) {
		this.database = database;
	}

	public void setProperty(String key,String value) {
		database.setProperty(key,value);
	}

	public DbArcana arcana() {
		return database.arcana();
	}

	public <K extends DbKey,V extends DbObject<K,V>> DbTableExt<K,V> newTable(DbDatabaseExt database,String tableName,DbKeySetter<K> keySetter,DbObjectFactory<K,V> objFactory) {
		return this.database.newTable(database,tableName,keySetter,objFactory);
	}

	public <K extends DbKey,V extends DbObject<K,V>> DbRecordExt<K,V> newRecord(DbTableExt<K,V> table,V obj,K key) {
		return database.newRecord(table,obj,key);
	}

	public <K extends DbKey,V extends DbObject<K,V>> DbRecordExt<K,V> newRecord(DbTableExt<K,V> table,V obj) {
		return database.newRecord(table,obj);
	}

	public Connection getConnection()
		throws SQLException
	{
		return database.getConnection();
	}

	public void runBeforeCommit(Runnable r) {
		database.runBeforeCommit(r);
	}

	public void runAfterCommit(Runnable r) {
		database.runAfterCommit(r);
	}

	public void runJustAfterCommit(Runnable r) {
		database.runJustAfterCommit(r);
	}

	public void ignoreRunnablesInThisTransaction() {
		database.ignoreRunnablesInThisTransaction();
	}

	public boolean isInTransaction() {
		return database.isInTransaction();
	}

	public void beginTransaction()
		throws SQLRuntimeException
	{
		database.beginTransaction();
	}

	public void commitTransaction()
		throws SQLRuntimeException
	{
		database.commitTransaction();
	}

	public void endTransaction()
		throws SQLRuntimeException
	{
		database.endTransaction();
	}

	public DbTransaction getTransaction() {
		return database.getTransaction();
	}


	public DbKeySetter<LongKey> newIdentityLongKeySetter(String fieldName) {
		return database.newIdentityLongKeySetter(fieldName);
	}

	public DbKeySetter<LongKey> newAssignedLongKeySetter(String fieldName) {
		return database.newAssignedLongKeySetter(fieldName);
	}

	public DbKeySetter<StringKey> newAssignedStringKeySetter(String fieldName) {
		return database.newAssignedStringKeySetter(fieldName);
	}

}
